<?php
/**
 * @package JoiCaddy
 * @copyright Авторские права (C) 2008-2010 Joostina team. Все права защищены.
 * @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
 * JoiCaddy - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
 * JoiCaddy основан на разработках SimpleCaddy от Henk von Pickartz
 */

defined('_VALID_MOS') or die();



$act = mosGetParam($_REQUEST, 'act', '');
$directory = mosGetParam($_REQUEST, 'directory' );

switch ($act) {
    case "go":
        convert_boss_base($directory);
	break;
    default:
	show_convertor();
}
function show_convertor(){
    $database = database::getInstance();
    $directories = $database->setQuery( "SELECT id, name FROM #__boss_config" )->loadObjectList();
  ?>  
<div style="width: 100%; height: 400px; text-align: center; vertical-align: middle; margin-top: 100px;">
    <form action="index2.php?option=com_boss_convertor" method="post" name="adminForm">
        <select name="directory">
        <?php  
        foreach($directories as $directory){
            ?>
            <option value="<?php echo $directory->id; ?>"><?php echo $directory->name; ?></option>
            <?php  
        }
        ?>
        </select>
        <input type="submit" value="Поехали!" class="button" />
        <input type="hidden"  value="go" name="act" />
    </form>

</div>
  <?php  
}
function convert_boss_base($directory){
    $database = database::getInstance();
    
     //создание таблицы конфигурации плагинов
  $database->setQuery("
            CREATE TABLE IF NOT EXISTS `#__boss_plug_config` (
            `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
            `directory` INT( 11 ) NOT NULL ,
            `plug_type` VARCHAR( 11 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
            `plug_name` VARCHAR( 30 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
            `title` VARCHAR( 30 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
            `value` VARCHAR( 30 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
            INDEX (  `directory` ,  `plug_type` ,  `plug_name` )
            ) ENGINE = MYISAM ;
        ");
  $database->query();
    if ($database->getErrorNum()) {
            echo $database->stderr();
            return false;
    }

  $database->setQuery("
            ALTER IGNORE TABLE `#__boss_config` DROP `max_image_size`;
        ");
  $database->query();
    if ($database->getErrorNum()) {
            echo $database->stderr();
            return false;
    }
    
  $database->setQuery("
            ALTER IGNORE TABLE `jos_boss_config` DROP `max_width`;
        ");
  $database->query();
    if ($database->getErrorNum()) {
            echo $database->stderr();
            return false;
    }
    
  $database->setQuery("
            ALTER IGNORE TABLE `jos_boss_config` DROP `max_height`;
        ");
  $database->query();
    if ($database->getErrorNum()) {
            echo $database->stderr();
            return false;
    }
    
  $database->setQuery("
            ALTER IGNORE TABLE `jos_boss_config` DROP `max_width_t`;
        ");
  $database->query();
    if ($database->getErrorNum()) {
            echo $database->stderr();
            return false;
    }
    
  $database->setQuery("
            ALTER IGNORE TABLE `jos_boss_config` DROP `max_height_t`;
        ");
  $database->query();
    if ($database->getErrorNum()) {
            echo $database->stderr();
            return false;
    }
    
  $database->setQuery("
            ALTER IGNORE TABLE `jos_boss_config` DROP `nb_images`;
        ");
  $database->query();
    if ($database->getErrorNum()) {
            echo $database->stderr();
            return false;
    }
    
  $database->setQuery("
            ALTER IGNORE TABLE `jos_boss_config` DROP `tag`;
        ");
  $database->query();
    if ($database->getErrorNum()) {
            echo $database->stderr();
            return false;
    }
    
  $database->setQuery("
            ALTER IGNORE TABLE `jos_boss_config` DROP `image_display`;
        ");
  $database->query();
    if ($database->getErrorNum()) {
            echo $database->stderr();
            return false;
    }

    
  $database->setQuery("
            ALTER IGNORE TABLE `jos_boss_config` ADD `rating` varchar(50) NOT NULL;
        ");
  $database->query();
    if ($database->getErrorNum()) {
            echo $database->stderr();
            return false;
    }
    


  //ALTER TABLE  `jos_boss_config` ADD  `sdsdsd` INT NOT NULL
    //ALTER TABLE `jos_boss_config` DROP `sdsdsd`;
    //ALTER TABLE  `jos_boss_config` CHANGE  `rating`  `rating` VARCHAR( 51 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL
}
?>
